package controller.v1;

import com.usian.apis.wemedia.WmNewsControllerApi;
import com.usian.model.admin.dtos.NewsAuthDto;
import com.usian.model.common.dtos.ResponseResult;
import com.usian.model.media.dtos.WmNewsDto;
import com.usian.model.media.dtos.WmNewsPageReqDto;
import com.usian.model.media.pojos.WmNews;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import service.WmNewsService;

import java.util.List;

@RestController
@RequestMapping("/wemedia/api/v1/news")
public class WmNewsController implements WmNewsControllerApi {
    @Autowired
    private WmNewsService wmNewsService;

    @PostMapping("/list")
    @Override
    public ResponseResult findPage(@RequestBody WmNewsPageReqDto dto) {
        return wmNewsService.findPage(dto);
    }

    @PostMapping("/submit")
    @Override
    public ResponseResult submitNews(@RequestBody WmNewsDto dto) {
        //判断当前文件的状态
        if(dto.getStatus().equals(WmNews.Status.SUBMIT)){
            //提交状态
            return wmNewsService.submitNews(dto,dto.getStatus());
        }else {
            //草稿状态
            return wmNewsService.submitNews(dto,dto.getStatus());
        }
    }
    @GetMapping("/one/{id}")
    @Override
    public ResponseResult findByIdNews(@PathVariable Integer id) {
        return wmNewsService.findByIdNews(id);
    }

    @GetMapping("/getone/{id}")
    @Override
    public WmNews findById(@PathVariable Integer id) {
        return wmNewsService.getById(id);
    }


    @PostMapping("/updateWmnews")
    @Override
    public ResponseResult updateWmNews(@RequestBody WmNews wmNews) {

        return wmNewsService.updateStatusAndReason(wmNews);
    }


    @GetMapping("/findRelease")
    @Override
    public List<Integer> findRelease() {
        return wmNewsService.findRelease();
    }

    @PostMapping("/findList")
    @Override
    public ResponseResult findList(NewsAuthDto dto) {
        return wmNewsService.findList(dto);
    }
}
